/**
 * @ignore
 */
Ext.data.ProxyMgr.registerType("settingsstorage",
    Ext.extend(Ext.data.LocalStorageProxy, {
    	id  : 'netgis-settings-storage'
		/*
        ,create: function(operation, callback, scope) {
        	Ext.data.LocalStorageProxy.create.call(this, operation, callback, scope);
        }

        ,read: function(operation, callback, scope) {
            var thisProxy = this;
        }

        ,update: function(operation, callback, scope) {
        }

        ,destroy: function(operation, callback, scope) {
        }
        */
    })
);

/**
 * @class NG.models.Settings
 * @extends Ext.data.Model
 * 
 * Default Settings handled by app.DEFAULT_SETTINGS. 
 * Application settings can be retrieved by app.getSettings() method.<br>
 */
NG.models.Settings = Ext.regModel('NG.models.Settings', {
	/**
	 * Fields: <br>
	 * <li>name
	 * <li>password
	 * <li>email
	 * <li>url
	 * <li>language
	 * <li>tileSize: Integer. Default value is 256.
	 * <li>useCache: Boolean. Default value is true.
	 * <li>cacheTimeout
	 * <li>showZoomControl: Boolean. Default value is true.
	 * <li>offline: Boolean. Default value is false.
	 * <li>lineColor: String. Default value is '0000FF'.
	 * 
	 * @property fields
	 * @type Array
	 */
    fields: [
        {name: 'id'},
        {name: 'name',     type: 'string'},
        {name: 'password', type: 'password'},
        {name: 'email',    type: 'string'},
        {name: 'url',      type: 'string'},
        {name: 'language', type: 'string'},
        {name: 'tileSize', type: 'int', defaultValue: 256},
        {name: 'useCache', type: 'boolean', defaultValue: true},
        {name: 'cacheTimeout', type: 'int', defaultValue: 30}, //unit is minute
        {name: 'showZoomControl', type: 'boolean', defaultValue: true},
        {name: 'offline',	type: 'boolean', defaultValue: false},
        {name: 'lineColor',	type: 'string', defaultValue: '0000FF'} //blue
    ],
    
    /**
     * 
     * @return {String}
     */
    getName: function (){return this.data.name;},

    /**
     * 
     * @return {String}
     */
    getPassword: function (){return this.data.password;}, 

    /**
     * 
     * @return {String}
     */
    getEmail: function (){return this.data.email;}, 

    /**
     * 
     * @return {String}
     */
    getUrl: function (){return this.data.url;}, 

    /**
     * 
     * @return {String}
     */
    getLanguage: function (){return this.data.language;},

    /**
     * 
     * @return {String}
     */
    getLineColor: function (){return this.data.lineColor;},
    
    /**
     * 
     * @return {Number} If less than 1 than 256. 
     */
    getTileSize: function (){
    	var tileSize = this.data.tileSize;
    	if (!Ext.isNumber(tileSize) || tileSize < 1) {
    		tileSize = 256;
    	}
    	return tileSize;
    }, 
    
    /**
     * 
     * @return {Boolean} Use cache or not.
     */
    useCache: function (){return this.data.useCache;},
    

    /**
     * 
     * @return {Number}
     */    
    getCacheTimeout: function (){return this.data.cacheTimeout;},
    
    /**
     * 
     * @return {Boolean} Whether show openlayers zoom control on map
     */
    showZoomControl: function (){return this.data.showZoomControl;},
    
    /**
     * 
     * @return {Boolean} Offline is enabled or not.
     */
    offlineEnabled: function(){return this.data.offline == true;},
    
    /**
     * If tileSize is not a number default tilesize is 256.
     * 
     * @return {OpenLayers.Size}
     */
    createOpenLayersTileSize: function (){
    	var tileSize = this.getTileSize();
    	return new OpenLayers.Size(tileSize, tileSize);
    },
    
    /**
     * @ignore
     */
   	proxy: {
        type: 'localstorage',
        id  : 'netgis-settings-storage'
    }
});

/**
 * 
 * @singleton NG.stores.settings
 * @type Ext.data.Store
 */
NG.stores.settings = new Ext.data.Store({
    model: "NG.models.Settings",
    autoLoad : true
});

/**
 * @class NG.models.Language
 * @extends Ext.data.Model
 * Fields:<br>
 * <li>language
 * <li>title
 */
NG.models.Language = Ext.regModel('NG.models.Language', {

	/**
	 * Fields:<br>
	 * <li>language
	 * <li>title
	 * 
	 * @property fields
	 * @type Array
	 */
	fields: [
	         {name: 'language', type: 'string'},
	         {name: 'title', type: 'string'}
    ]
});

/**
 * Default elements:
 * <li>TR
 * <li>EN
 * 
 * @singleton NG.stores.language
 * @type Ext.data.JsonStore
 */
NG.stores.language = new Ext.data.JsonStore({
    data : [
         {language: 'TR', title: 'Türkçe'},
         {language: 'EN', title: 'English'}
    ],
    model : 'NG.models.Language',
    autoLoad : true,
    autoDestroy : true
});
